package cn.memset.code.functionInterface;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class OperatorExample {
    public static void main(String[] args) {
        testUnaryOperator();
        testBinaryOperator();
    }

    public static void testUnaryOperator() {
        List<String> provinces = Arrays.asList("Guangdong", "Jiangsu", "Guangxi", "Jiangxi", "Shandong");

        // 将省份的字母转换成大写字母
        provinces.replaceAll(s -> s.toUpperCase());
        System.out.println(provinces);

        // 将省份的字母转换成小写字母
        provinces.replaceAll(String::toLowerCase);
        System.out.println(provinces);
    }

    public static void testBinaryOperator() {
        List<Integer> values = Arrays.asList(1, 3, 5, 7, 11);

        // 使用 reduce 方法进行求和：0+1+3+5+7+11 = 27
        int sum = values.stream()
                .reduce(0, (a, b) -> a + b);

        System.out.println(sum);
    }
}
